package com.spark.sniffer;

import com.spark.sniffer.logging.api.Logger;
import com.spark.sniffer.logging.api.LoggerFactory;
import com.spark.sniffer.logging.config.Config;
import com.spark.sniffer.logging.core.LogLevel;

/**
 * Agent启动参数
 * 
 * @author cobe
 * @date 2020/03/16
 */
public class AgentArgs {
    private static final Logger log = LoggerFactory.getLogger(AgentArgs.class);

    private AgentArgs() {}

    /**
     * 是否以简单模式启动，默认是。 简单模式下，输出日志较为简单
     */
    private static boolean simpleTracing = false;

    /**
     * 是否debug模式，默认否。debug模式下，日志输出debug级别
     */
    private static boolean debugEnabled = false;

    /**
     * 是否本地开发模式。本地模式下，acm不覆盖
     */
    private static boolean local = false;

    /**
     * 根据Agent启动参数进行初始化
     * 
     * @param args agent启动参数，格式类似：-javaagent:spark-sniffer-agent.jar=more,debug,local
     */
    public static void init(String args) {
        log.info("Starting up with args [{}]...", args);

        if (args == null || args.trim().isEmpty()) {
            return;
        }

        args = args.toLowerCase();
        if (args.contains("more")) {
            simpleTracing = false;
        }
        if (args.contains("debug")) {
            debugEnabled = true;
            Config.Logging.LEVEL = LogLevel.DEBUG;
        }
        if (args.contains("local")) {
            local = true;
        }
    }

    public static boolean isSimpleTracing() {
        return simpleTracing;
    }

    public static boolean isDebugEnabled() {
        return debugEnabled;
    }

    public static boolean isLocal() {
        return local;
    }

}
